<template>
	<view class="pd kkxczxresr pr">
		<view class="z6 fz30">
			请设置头像昵称
		</view>
		<view class="pt20 pm20 display-flex mt20 fz30 bbm">
			<view class="flex-1 vertical-center tl">
				头像
			</view>
			<view class="">
				<image v-if="form.headPortrait" :src="form.headPortrait" class="czxczerexze"></image>
			</view>
			<button open-type="chooseAvatar" @chooseavatar="kkfdssdtret" class="dfsdtrxcrett"></button>
		</view>
		<view class="pt20 pm20 display-flex  fz30 bbm">
			<view class=" vertical-center tl">
				昵称
			</view>
			<view class="flex-1"> 
				<input v-model="form.nickname" 
				type="nickname" placeholder="请输入昵称" class="tr dfddftryy"  />
			</view>
		</view>

		<view class="mt100">
			<button type="primary" class="w100" @tap="tijiaos">保存</button>
		</view>
	</view>
	<view class="lxczxcrere">

	</view>

</template>
<script lang="ts" setup>
	import { hf, dxrequest, upImg, bUrl, outInt,callBack } from "@/util/index"
	import { ref } from "vue"
	const form = ref({
		headPortrait: "",
		nickname: ""
	})
	const openid = uni.getStorageSync("openid")

	const kkfdssdtret = (data) => {
		uni.showLoading({
			title:"加载中..."
		})
		uni.uploadFile({
			url: 'https://duxinggj.com/public/Upimg', //仅为示例，非真实的接口地址
			filePath: data.detail.avatarUrl,
			name: 'file',
			formData: {
				'typeName': '独行工匠'
			},
			success: async (uploadFileRes) => {
				const data = JSON.parse(uploadFileRes.data)
				form.value.headPortrait = data.data.imgurl
				uni.hideLoading()
			},
		})
	}
	const tijiaos = async () => {
		if (!form.value.headPortrait) {
			uni.showToast({
				icon: "none",
				title: "请上传头像"
			})
			return
		}
		uni.showLoading({
			title:"操作中..."
		})
		const { data } = await dxrequest("dxgj/api/gxuser", form.value, "put")
		uni.hideLoading()
		uni.showToast({
			title:"保存成功！"
		})
		setTimeout(a=>{
			callBack()
		},1000)
	}
	
	const initsd = async () => {
		uni.showLoading({
			title:"加载中..."
		})
		const { data } = await dxrequest("dxgj/api/getUserInfo" )
		form.value ={
			headPortrait:data.headPortrait,
			nickname:data.nickname
		} 
		uni.hideLoading()
	}
	initsd()
</script>

<style scoped>
	.kkxczxresr {
		padding-top: 200rpx;
	}

	.lxczxcrere {
		position: fixed;
		left: 0;
		top: 0;
		width: 100%;
		height: 100%;
		background: #fff;
	}

	.czxczerexze {
		width: 120rpx;
		height: 120rpx;
		border-radius: 50%;
		background: #f2f2f2;
	}

	.dfsdtrxcrett {
		position: absolute;
		left: 0;
		top: 0;
		width: 100%;
		height: 100%;
		opacity: 0;
	}

	.dfddftryy {
		height: 80rpx;
	}
</style>